import xtRequest from "@/api/index"
import { IQueryPage, IUserList, IAddPageDate } from "@/types/userType"
// 获取用户列表
export function getUserList(queryPage: IQueryPage) {
  return xtRequest.post<IUserList>({
    url: `/${
      queryPage.pageName.toLocaleLowerCase() == "user"
        ? "users"
        : queryPage.pageName.toLocaleLowerCase()
    }/list`,
    data: queryPage.queryInfo,
  })
}

// 删除数据
export function delateUserList(pageName:string, id:number) {
  return xtRequest.delete({
    url: `/${pageName.toLocaleLowerCase() == "user"
    ? "users"
    : pageName.toLocaleLowerCase()}/${id}`
  })
}

// 新增数据
export function addPageDate(queryPage: IAddPageDate) {
  console.log(`/${
    queryPage.pageName.toLocaleLowerCase() == "user"
      ? "users"
      : queryPage.pageName.toLocaleLowerCase()
  }`)
  console.log(queryPage.addInfo)
  return xtRequest.post({
    url: `/${
      queryPage.pageName.toLocaleLowerCase() == "user"
        ? "users"
        : queryPage.pageName.toLocaleLowerCase()
    }`,
    data: queryPage.addInfo,
  })
}

// 修改数据
export function editPageDate(pageDage: any) {
  console.log( `/${
    pageDage.pageName.toLocaleLowerCase() == "user"
      ? "users"
      : pageDage.pageName.toLocaleLowerCase()
  }/${pageDage.id}`)
  return xtRequest.patch({
    url: `/${
      pageDage.pageName.toLocaleLowerCase() == "user"
        ? "users"
        : pageDage.pageName.toLocaleLowerCase()
    }/${pageDage.id}`,
    data: pageDage.update,
  })
}
